/**
 *    @file       ini_config.h
 *
 *    @brief      
 *    @details
 *
 *    @version    1.0
 *    @date       12/11/2012 10:51:16 PM
 *
 *    @author     Theophilus, wangtf418@gmail.com
 */
#ifndef _BF_INI_CONFIG_H_
#define _BF_INI_CONFIG_H_
#include <string>
#include <map>
#include "comdef.h"

class ini_config
{
public:
	ini_config();
	ini_config(const std::string &filename);
	virtual ~ini_config();

public:
	bf_int_t init();
	void set_config_filename(const std::string &filename);

public:
	bf_int_t read_item(const std::string &section, const std::string &key, const std::string &def_value, std::string &value_out);
	bf_int_t write_item(const std::string &section, const std::string &key, const std::string &value);

public:
	bf_int_t read_int_item(const std::string &section, const std::string &key, bf_int64_t def_value, bf_int64_t &value_out, bf_int64_t min_val = BF_INT64_MIN, bf_int64_t max_val = BF_INT64_MAX);
	bf_int_t write_int_item(const std::string &section, const std::string &key, bf_int64_t value);

public:
	bf_int_t read_ip_item(const std::string &section, const std::string &key, const std::string &def_value, bf_uint_t &value_out);
	bf_int_t write_ip_item(const std::string &section, const std::string &key, bf_uint_t value);
protected:
	bf_int_t load_config_file();
	bf_int_t dump_config_file();
	void trim(std::string &str);

protected:
	typedef std::map<std::string, std::string> parameters_t;
	std::map<std::string, parameters_t> m_sections;
	std::string m_filename;
};

#endif

